<?php 
 include_once dirname(__FILE__)."/config.php";
 class grade_principal{
		 protected $_result;
		 protected $_cnn;
		 protected $_code_grade;
		 protected $_prefix_grade;
		 protected $_libelle;
		 public function get_name_table(){ return "grade";}
		 public function get_name_code_grade(){ return "code_grade";}
		 public function get_name_prefix_grade(){ return "prefix_grade";}
		 public function get_name_libelle(){ return "libelle";}
		 public function set_code_grade($parametre){  $this->_code_grade=$parametre;}	
		 public function set_prefix_grade($parametre){  $this->_prefix_grade=$parametre;}	
		 public function set_libelle($parametre){  $this->_libelle=$parametre;}	
		 public function get_result(){ return $this->_result;}
		 public function get_code_grade(){ return $this->_code_grade;}
		 public function get_prefix_grade(){ return $this->_prefix_grade;}
		 public function get_libelle(){ return $this->_libelle;}
public function __construct(){

		 	$this->_cnn=new databaseconnect();

		 }

 public function INSERT()
{

$sql=" INSERT INTO 
 grade(
			prefix_grade,
			libelle)
 VALUES(
			'".$this->_prefix_grade."',
			'".$this->_libelle."')";

$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}

 public function UPDATE()
{

 $sql="";
if(!empty($this->_prefix_grade)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
prefix_grade='".$this->_prefix_grade."'";
}
if(!empty($this->_libelle)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
libelle='".$this->_libelle."'";
}
$sql="UPDATE 
grade SET 
 ".$sql."
								WHERE code_grade ='".$this->_code_grade."'";

$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}

 public function DELETE(){

 $sql="DELETE FROM 
grade 
 
									WHERE code_grade ='".$this->_code_grade."'";

$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}

 public function TRANCATE(){

 $sql="DELETE FROM 
grade ";

$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}

 public function SELECT($constraint="",$pagination="")
{

$sql=" SELECT 
 		code_grade,
		prefix_grade,
		libelle
 FROM 
 grade";
if($constraint){$sql.=" WHERE 1=1 ".$constraint;}if($pagination){$sql.=$pagination;}
$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}
public function fetch_object(){
$row=mysql_fetch_object($this->_result);
 if($this->_result){
 if($row){
		$this->_code_grade=$row->code_grade;
		$this->_prefix_grade=$row->prefix_grade;
		$this->_libelle=$row->libelle;
		return $row;
		}else{
					return false;
				}

			}else{
				//echo 'Erreur d\'execution de requette de selection';	
			}
			

		}

}
?>